<template>
    <div>
        <el-dialog v-model="ViewdialogVisible" width="80%" align-center destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>论文查看</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <div class="pt-[30px] pb-[20px] bg-white">
                <div class="px-[5px]  text-right" v-if="procInsId != null">
                    <el-link type="primary" @click="checkHistoryModalVisible = true">审核记录</el-link>
                </div>
                <el-tabs v-model="activeStep" class="demo-tabs">
                    <el-tab-pane label="基本信息" :name="0">
                        <div>
                            <!-- 基本信息 -->
                            <div class="bg-white mt-[10px]">
                                <BaseHead>基本信息</BaseHead>
                                <div class="p-[10px]">
                                    <el-descriptions title="" :column="2" border label-width="140">
                                        <el-descriptions-item label-class-name="gdlable" :span="2" label="名称">{{
            ruleForm.name
        }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="发表/出版时间">{{
                dateFormatter3(ruleForm.publishDate)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="发表/刊物论文集">{{
                ruleForm.magazineName
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="论文类型">{{
                formatmodeId(ruleForm.modeId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="所属单位">{{
                formatUnitId(ruleForm.unitId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="刊物级别">{{
                formatpaperLevelIdList(ruleForm.paperLevelIdList)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="收录类别">{{
                formatembodyTypeIdList(ruleForm.embodyTypeIdList)
            }}</el-descriptions-item>
                                        <el-descriptions-item
                                            v-if="ruleForm.embodyTypeIdList && ruleForm.embodyTypeIdList.length && ruleForm.embodyTypeIdList.includes('300601')"
                                            label-class-name="gdlable" label="SCI论文分区">{{
            ruleForm.sciPartition == 1 ? '一区' : ruleForm.sciPartition == 2 ? '二区' :
                ruleForm.sciPartition == 3 ? '三区' : scope.row.sciPartition == '4' ? '四区'
                    : ''
        }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable"
                                            v-if="ruleForm.embodyTypeIdList.includes('300601')" label="影响因子">{{
            ruleForm.factor
        }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="教育部统计归属">{{
                ruleForm.subjectClassId == 1 ? '社科类' : "科技类"
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="一级学科">{{
                formatsubjectId(ruleForm.subjectId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="项目来源">{{
                formatprojectSourceId(ruleForm.projectSourceId)
            }}</el-descriptions-item>
                                          <el-descriptions-item label-class-name="gdlable" label="论文链接地址">{{
            ruleForm.url
            }}</el-descriptions-item>
                                    </el-descriptions>
                                </div>
                            </div>
                            <!-- 详细信息 -->
                            <div class="bg-white mt-[10px]">
                                <BaseHead>详细信息</BaseHead>
                                <div class="p-[10px]">
                                    <el-descriptions title="" :column="2" border label-width="140">
                                        <el-descriptions-item label-class-name="gdlable" :span="2" label="发表范围">{{
            formatpublishRangeId(ruleForm.publishRangeId)
        }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="学校署名">{{
                ruleForm.schoolSign == '0' ? '第一单位' : '非第一单位'
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="卷期页">{{
                ruleForm.juanQiYe
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="DOI">{{
                ruleForm.doi
                                            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="ISSN号">{{
                                            ruleForm.issn
                                            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="CN号">{{
                                            ruleForm.claimId
                                            }}</el-descriptions-item>
                                              <el-descriptions-item label-class-name="gdlable" label="电子版附件">
                                                <template v-if="ruleForm.fileIds">
                                                <span>{{ruleForm.fileNames}}</span>    
                                                <el-link type="primary" style="margin-left: 8px;"
                                                    @click="downloadMet(ruleForm.fileIds)">下载</el-link>
                                                </template>
                                               
                                              </el-descriptions-item>
                                    </el-descriptions>
                                    
                                </div>
                            </div>
                            <!-- 作者信息 -->
                            <div class="bg-white mt-[10px]">
                                <BaseHead>作者信息</BaseHead>
                                <div class="p-[10px]">
                                    <el-table :data="tableData" border style="width: 100%">
                                        <el-table-column align="center" type="index" label="署名顺序" width="80" />
                                        <el-table-column align="center" prop="authorType" label="作者类型">
                                            <template #default="scope">
                                                {{
                                                scope.row.authorType == '1' ? '教师' : scope.row.authorType == '2' ? '学生'
                                                : '校外'
                                                }}</template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="authorName" label="作者姓名">

                                        </el-table-column>
                                        <el-table-column align="center" prop="eduLevelId" label="学历">
                                            <template #default="scope">
                                                <!-- {{
                                                formateduLevelId(scope.row.eduLevelId)
                                                }} -->
                                                <Feedback :id="scope.row.eduLevelId" :list="xlList">
                                                </Feedback>
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="titleId" label="职称">
                                            <template #default="scope">
                                                <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                                    :render-after-expand="false" disabled />
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="isTxAuthor" label="角色类型">
                                            <template #default="scope">
                                                <Feedback :id="scope.row.isTxAuthor" :list="lwzzList">
                                                </Feedback>
                                            </template>
                                        </el-table-column>

                                        <el-table-column align="center" prop="authorUnit" label="工作单位">
                                            <template #default="scope">
                                                <span v-if="scope.row.authorType == 3">{{scope.row.authorUnit }}</span>
                                                <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                                                    :mapping="['codeColumn', 'valueColumn']">
                                                </Feedback>
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="依托项目" :name="1">
                        <supportProjectView :productId="ruleForm.id"></supportProjectView>
                    </el-tab-pane>
                    <el-tab-pane label="转载情况" :name="2">
                        <situationReproductionView :productId="ruleForm.id"></situationReproductionView>
                    </el-tab-pane>
                    <el-tab-pane label="论文收录" :name="3">
                        <inclusionPaperView :productId="ruleForm.id"></inclusionPaperView>
                    </el-tab-pane>
                </el-tabs>

            </div>
        </el-dialog>
    </div>
    <CheckHistoryModal v-model="checkHistoryModalVisible" :procInsId="procInsId" :checker="checker"
        :checkDate="checkDate" />
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import supportProjectView from "@/views/achievement/components/supportProjectView.vue"
import inclusionPaperView from "@/views/achievement/components/inclusionPaperView.vue"
import situationReproductionView from "@/views/achievement/components/situationReproductionView.vue"
import { getCategory } from "@/api/system/category"
import CheckHistoryModal from "@/views/project/components/CheckHistoryModal.vue";

const ViewdialogVisible = defineModel();
const props = defineProps({
    xlList: Array,
    zcList: Array,
    zcgsdwList: Array,
    jbList: Array,
    xmlyList: Array,
    fbfwList: Array,
    kjxkflList: Array,
    skxkflList: Array,
    lwlx: Array,
    lbList: Array,
    lwzzList: Array,
    sydwList: Array,
})

const checkHistoryModalVisible = ref(false);
const procInsId = ref(null); //流程实例id
const checker = ref("");
const checkDate = ref("");

const ruleForm = reactive({
});
const tableData = reactive([
]);


const formatUnitId = (cellValue) => {
    if (props.zcgsdwList.length && cellValue) {
        return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
    } else {
        return ''
    }


}

const formatmodeId = (cellValue) => {
    if (props.lwlx.length && cellValue) {
        return props.lwlx.find(item => item.code == cellValue).name
    } else {
        return ''
    }

}
const formatsubjectId = (cellValue) => {
    if (ruleForm.subjectClassId == 2) {
        if (props.kjxkflList.length && cellValue) {
            return props.kjxkflList.find(item => item.id == cellValue) ? props.kjxkflList.find(item => item.id == cellValue).label : ''
        } else {
            return ''
        }
    } else {
        if (props.skxkflList.length && cellValue) {
            return props.skxkflList.find(item => item.id == cellValue) ? props.skxkflList.find(item => item.id == cellValue).label : ''
        } else {
            return ''
        }
    }
}
const formatprojectSourceId = (cellValue) => {
    if (props.xmlyList.length && cellValue) {
        return props.xmlyList.find(item => item.id == cellValue) ? props.xmlyList.find(item => item.id == cellValue).label : ''
    } else {
        return ''
    }


}
const formatpaperLevelIdList = (cellValue) => {
    console.log(cellValue, 'cellValue')
    console.log(props.jbList)
    let zcArr = []
    if (props.jbList.length && cellValue && cellValue.length > 0) {
        for (let i = 0; i < cellValue.length; i++) {
            console.log(props.jbList.find(item => item.code == cellValue[i]))
            zcArr[i] = props.jbList.find(item => item.code == cellValue[i]) ? props.jbList.find(item => item.code == cellValue[i]).name : ''
        }
        return zcArr.join('、')
    } else {
        return ''
    }


}

const formatembodyTypeIdList = (cellValue) => {
    let zcArr = []
    if (props.lbList.length && cellValue && cellValue.length > 0) {
        for (let i = 0; i < cellValue.length; i++) {
            zcArr[i] = props.lbList.find(item => item.code == cellValue[i]) ? props.lbList.find(item => item.code == cellValue[i]).name : null
        }
        zcArr = Array.from(zcArr).filter(function (element) {
            return element !== undefined && element !== null;
        });
        return zcArr.join('、')
    } else {
        return ''
    }


}

const formateduLevelId = (cellValue) => {
    if (props.xlList.length && cellValue) {
        return props.xlList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}

const formatpublishRangeId = (cellValue) => {
    if (props.fbfwList.length && cellValue) {
        return props.fbfwList.find(item => item.code == cellValue).name
    } else {
        return ''
    }
}

const getRuleForm = (i) => {
    if (i.authorList && i.authorList.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.authorList); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    procInsId.value = ruleForm.processInstanceId;
    checker.value = ruleForm.checker;
    checkDate.value = ruleForm.checkdate;
}
const activeStep = ref(0)
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}
defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
